/**
 * Description:
 * Class Name:RandomAccessFileTest
 * Date:2022/5/2 16:37
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第15章_输入输出._15_7_RandomAccessFile;

import java.io.IOException;
import java.io.RandomAccessFile;

public class RandomAccessFileTest {
    public static void main(String[] args) {
        String path = "./src/" + RandomAccessFileTest.class.getName().replace(".", "/") + ".java";
        try (
                var raf = new RandomAccessFile(path, "r")
                ){
            // 获取该文件对象指针的位置，初始位置是0
            System.out.println("RandomAccessFile的文件指针的初始位置：" + raf.getFilePointer());
            // 移动raf的文件记录指针的位置
            raf.seek(300);

            var bbuf = new byte[1024];
            var hasRead = 0;
            while ((hasRead = raf.read(bbuf)) > 0){
                System.out.println(new String(bbuf, 0, hasRead));
            }
        }
        catch (IOException ioException){
            ioException.printStackTrace();
        }
    }
}
